<template>
  <div>
    <div class="t-nps-box">
      <span
        v-for="n in table.level"
        class="item"
        @mousemove="setCurrentHoverValue(n)"
        @click="handleClick(n)"
        :class="[currentHoverValue >= n ? 'hover' : '', changeValue === n ? 'active' : '']"
      >
        {{ n }}
      </span>
    </div>
    <div class="tip-text">
      <div>
        {{ table.copyWriting.min }}
      </div>
      <div>
        {{ table.copyWriting.max }}
      </div>
    </div>
  </div>
</template>

<script>
import mixin from '../mixin'

export default {
  name: 'TNps',
  mixins: [mixin],
  props: {
    table: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      currentHoverValue: 0,
      dataValue: {}
    }
  },
  watch: {
    table: {
      handler(value) {
        this.initValue()
      },
      deep: true
    }
  },
  methods: {
    // 初始化矩阵value为二维数组
    initValue() {
      this.dataValue = this.value
    },
    setCurrentHoverValue(val) {
      if (val < this.changeValue) {
        return
      }
      this.currentHoverValue = val
    },
    handleClick(val) {
      this.currentHoverValue = val
      this.changeValue = val
    }
  }
}
</script>

<style lang="scss">
.tip-text {
  font-size: 13px;
  color: #8a8f97;
  margin-top: 5px;
  display: flex;
  justify-content: space-between;
}

.t-nps-box {
  display: flex;
  align-items: center;

  .item {
    transition: all 0.3s ease;
    height: 40px;
    line-height: 40px;
    flex: 1;
    width: 1px;
    text-align: center;
    background-color: #f2f3f9;
    display: inline-block;
    color: #314666;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    margin-right: 8px;
    cursor: pointer;
  }

  .hover {
    background-color: var(--form-theme-hover-color);
  }

  .active {
    background-color: var(--form-theme-color);
    color: #fff;
  }
}

// 变亮
@function tint($color, $percentage) {
  @return mix(white, $color, $percentage);
}
</style>
